package app.view.mediators
{
	import app.AppConstants;
	import app.view.renderers.RolloverLabel;
	
	import flare.vis.data.DataSprite;
	
	import flash.events.Event;
	
	import mx.core.Application;
	import mx.managers.PopUpManager;
	
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;

	public class InfoPopUpMediator extends Mediator
	{
		public static const NAME:String = "InfoPopUp";
		private var application:Application;
		
		public function InfoPopUpMediator(application:Application){
			this.application = application;
			super(NAME, new RolloverLabel());
		}
		
		
		override public function listNotificationInterests():Array{
			return [	AppConstants.EDGE_ROLL_OUT,
						AppConstants.EDGE_ROLL_OVER,
						AppConstants.EDIT_CLOSE
												]
		}
		
		override public function handleNotification(note:INotification):void{
			
			switch( note.getName() ){
				
				case AppConstants.EDGE_ROLL_OUT:
					hide()
					break;
					
				case AppConstants.EDGE_ROLL_OVER:
					view.data = DataSprite( note.getBody() ).data;
					show();
					break;
					
				case AppConstants.EDIT_CLOSE:
					hide();
					break;
				
			}
		}
		
		private function onEnterFrame(event:Event):void{
			position();
		}
		
		public function show(  ):void{
			//view.addEventListener(FlexEvent.CREATION_COMPLETE, onCreationComplete);
			view.addEventListener(Event.ENTER_FRAME, onEnterFrame);
			PopUpManager.addPopUp( view, application, false );
		}
		private function position():void{
			view.x = application.mouseX + 3;
			view.y = application.mouseY - view.height - 3;
		}
		
		public function hide(  ):void{
			view.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
			PopUpManager.removePopUp( view );
			
		}
		
		private function get view():RolloverLabel{
			return RolloverLabel(viewComponent);
		}
		
	}
}